<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
  <title></title>
   <base href="__STATIC__/Admin/">
  <link href="styles/general.css" rel="stylesheet" type="text/css" />
  <link href="styles/main.css" rel="stylesheet" type="text/css" />
  <script type="text/javascript" src="js/utils.js"></script>
  <script type="text/javascript" src="js/selectzone.js"></script>
  <script type="text/javascript" src="js/colorselector.js"></script>
  <!-- <script type="text/javascript" src="js/calendar.php?lang="></script> -->
</head>
<body>
<h1>
  <span class="action-span"><a href="{:url('Admin/Goods/goods_list')}">商品列表</a></span>
  <span class="action-span1"><a href="{:url('Admin/Index/main')}">SHOP 管理中心 </a> </span><span id="search_id" class="action-span1"> - 编辑商品信息 </span>
  <div style="clear:both"></div>
</h1>

<div class="tab-div">
    <!-- tab bar -->
    <div id="tabbar-div">
      <p>
        <span class="tab-front" id="general-tab">通用信息</span>
    <span class="tab-back" id="detail-tab">详细描述</span>
    <span class="tab-back" id="mix-tab">其他信息</span>
    <span class="tab-back" id="properties-tab">商品属性</span>
    <!-- <span class="tab-back" id="gallery-tab">商品相册</span> -->
      </p>
    </div>

    <!-- tab body -->
    <div id="tabbody-div">
      <form enctype="multipart/form-data" action="{:url('Admin/Goods/goods_add')}" method="post" name="theForm">  
     <!-- 通用信息 -->
        <table width="90%" id="general-table" align="center" style="display: table;">
      <tbody>
        <tr>
          <td class="label">商品名称：</td>
          <td><input type="text" name="goods_name" value="" size="30"><span class="require-field">*</span></td>
        </tr>
        <tr>
          <td class="label">商品货号： </td>
          <td><input type="text" name="goods_sn" value="" size="20"><span id="goods_sn_notice"></span><br>
          <span class="notice-span" style="display:block" id="noticeGoodsSN">如果您不输入商品货号，系统将自动生成一个唯一的货号。</span></td>
      </tr>
      <tr>
        <td class="label">商品分类：</td>
        <td>
          <select name="cat_id" id="select">
            <option value="">请选择分类</option>
            {foreach $cat as $v}
              <option value="{$v.cat_id}"><?php echo str_repeat("&nbsp;&nbsp;&nbsp;├",substr_count($v['new'],"-")-1) ?>{$v.cat_name}</option>
            {/foreach} 
          </select>
        </td>
      </tr>
      <tr>
        <td class="label">商品品牌：</td>
        <td>
          <select name="brand_id">
            <option value="0" selected="">请选择...</option>
            {foreach $brand as $v}
              <option value="{$v.brand_id}">{$v.brand_name}</option>
            {/foreach}
          </select>
        </td>
      </tr>
      <tr>
        <td class="label">本店售价：</td>
        <td><input type="text" name="goods_price" value="" size="20">
        <span class="require-field">*</span></td>
      </tr>
      <tr>
        <td class="label"><label for="is_promote">
              <input type="checkbox" id="is_promote" name="is_promote" value="1" checked="checked"> 促销价：</label></td>
            <td id="promote_3">
              <input type="text" id="promote_1" name="promote_price" value="" size="20"></td>
          </tr>
       <tr>
        <td class="label">排序：</td>
        <td>
          <input type="text" name="sort_order" maxlength="40" size="15" value="50">
        </td>
      </tr>
          <tr>
            <td class="label">上传商品图片：</td>
            <td>
              <input type="file" name="img_url" size="35">
            </td>
      </tr>
      </tbody></table>

        <!-- 详细描述 -->
         <table width="90%" id="detail-table" style="display: none;">
        <tbody>
          <tr>
            <td>
              <textarea id="editor" type="text/plain" name="goods_desc" style="width:1024px;height:300px;border:3px solid #ccc;"></textarea>
            </td>
          </tr>
        </tbody>
      </table>
        <!-- 其他信息 -->
        <table width="90%" id="mix-table" style="display: none;" align="center">
          <tbody><tr>
            <td class="label">商品重量：</td>
            <td><input type="text" name="goods_weight" value="" size="20"><span>&nbsp&nbsp克</span></td>
          </tr>
          <tr>
            <td class="label"> 商品库存数量：</td>
            <td><input type="text" name="goods_number" value="" size="20"><br></td>
          </tr>
          <tr>
            <td class="label">加入推荐：</td>
            <td>
              <input type="checkbox" name="is_best" value="1" checked="checked">精品 
              <input type="checkbox" name="is_new" value="1" checked="checked">新品 
              <input type="checkbox" name="is_hot" value="1" checked="checked">热销
            </td>
          </tr>
          <tr id="alone_sale_1">
            <td class="label" id="alone_sale_2">上架：</td>
            <td id="alone_sale_3"><input type="checkbox" name="is_sale" value="1" checked="checked"> 打勾表示允许销售，否则不允许销售。</td>
          </tr>
          <tr>
            <td class="label">能作为普通商品销售：</td>
            <td><input type="checkbox" name="is_alone_sale" value="1" checked="checked"> 打勾表示能作为普通商品销售，否则只能作为配件或赠品销售。</td>
          </tr>
          <tr>
            <td class="label">是否为免运费商品</td>
            <td><input type="checkbox" name="is_shipping" value="1" checked="checked"> 打勾表示此商品不会产生运费花销，否则按照正常运费计算。</td>
          </tr>
          <tr>
            <td class="label">商品简单描述：</td>
            <td><textarea name="goods_brief" cols="40" rows="3"></textarea></td>
          </tr>
          <tr>
            <td class="label">
            <a href="javascript:;" title="点击此处查看提示信息"><img src="images/notice.gif" width="16" height="16" border="0" alt="点击此处查看提示信息"></a> 商家备注： </td>
            <td><textarea name="seller_note" cols="40" rows="3"></textarea><br>
            <span class="notice-span" style="display:block" id="noticeSellerNote">仅供商家自己看的信息</span></td>
          </tr>
        </tbody></table>

        <!-- 商品属性 -->
         <table width="90%" id="properties-table" style="display: none;" align="center">
      
        <tr>
          <td class="label">商品类型：</td>
          <td>
            <select name="type_id" class="goods_type">
              <option value="0">请选择商品类型</option>
              {foreach $type as $v}
              <option value="{$v.type_id}">{$v.type_name}</option>  
              {/foreach}              
            </select><br>
            <span class="notice-span" style="display:block" id="noticeGoodsType">请选择商品的所属类型，进而完善此商品的属性</span>
          </td>
        </tr>  
        <tbody style="display: none;" class="togg">

        </tbody></table>
        
        <!-- 商品相册 -->
        <!-- <table width="90%" id="gallery-table" style="display: none;" align="center">
          <tbody>
          <tr><td>&nbsp;</td></tr>
          <tr>
            <td>
              <a href="javascript:;">[+]</a>图片描述 <input type="text" name="img_desc[]" size="20" />上传文件 <input type="file" name="img_url[]" multiple>
            </td>
          </tr>
        </tbody></table> -->
        <div class="button-div">
          <input type="submit" value=" 确定 " class="button">
          <input type="reset" value=" 重置 " class="button">
        </div>
      </form>
    </div>
</div>


<div id="footer">
  版权所有 &copy; 2006-2013 
</div>
<script src="jquery.js"></script>
<script>
    $(".goods_type").on('change',function(){
        var id = $(this).val();
        $.ajax({
            url:"{:url('Admin/Goods/get_attr')}",
            type:'get',
            data:{id:id},
            dataType:'json',
            success:function(e){              
                var arr = e;
                if(id == 0){
                    $(".togg").empty();
                    $(".togg").hide();
                }else{
                    $(".togg").empty();
                    $(".togg").show();
                    for(var i=0;i<arr.length;i++){
                        if(arr[i]['attr_input_type']==0){
                              $(".togg").append('<tr><td class="label">'+arr[i]['attr_name']+'</td><td><input type="text" name="attr_value[]"><input type="hidden" name="attr_id[]" value="'+arr[i]['attr_id']+'"></td></tr>');        
                        }
                        if(arr[i]['attr_input_type']==1){
                                var name = arr[i]['attr_name'];
                                var value = arr[i]['attr_values'];
                                var arrs = new Array();
                                var str ='';
                                arrs = value.split(",");
                               for(var l=0;l<arrs.length;l++){
                                  str += '<option value="'+arrs[l]+'">'+arrs[l]+'</option>';
                               }
                                $(".togg").append('<tr><td class="label">'+name+'</td><td><select name="attr_value[]">'+str+'</select><input type="hidden" name="attr_id[]" value="'+arr[i]['attr_id']+'"></td></tr>');                              
                        }             
                    }

                }
            }
        });
    });
</script>
<script type="text/javascript" src="js/tab.js"></script>
<script type="text/javascript">
  function addImg(obj){
      var src  = obj.parentNode.parentNode;
      var idx  = rowindex(src);
      var tbl  = document.getElementById('gallery-table');
      var row  = tbl.insertRow(idx + 1);
      var cell = row.insertCell(-1);
      cell.innerHTML = src.cells[0].innerHTML.replace(/(.*)(addImg)(.*)(\[)(\+)/i, "$1removeImg$3$4-");
    }

    function removeImg(obj){
      var row = rowindex(obj.parentNode.parentNode);
      var tbl = document.getElementById('gallery-table');
      tbl.deleteRow(row);
    }

    function dropImg(imgId){
      Ajax.call('goods.php?is_ajax=1&act=drop_image', "img_id="+imgId, dropImgResponse, "GET", "JSON");
    }

    function dropImgResponse(result){
      if (result.error == 0){
          document.getElementById('gallery_' + result.content).style.display = 'none';
      }
    }

</script>

</body>
</html>